package com.hmall.user.service;

import com.hmall.pojo.User;
import com.baomidou.mybatisplus.extension.service.IService;
import io.seata.rm.tcc.api.BusinessActionContext;
import io.seata.rm.tcc.api.BusinessActionContextParameter;
import io.seata.rm.tcc.api.LocalTCC;
import io.seata.rm.tcc.api.TwoPhaseBusinessAction;

@LocalTCC
public interface IUserService extends IService<User> {
    /**
     * 下单扣款 TCC -- try
     * @param userId
     * @param money
     */
    @TwoPhaseBusinessAction(name = "deductMoney",commitMethod = "confirm",rollbackMethod = "cancel")
    void deductMoney(@BusinessActionContextParameter(paramName = "userId") Long userId,
                     @BusinessActionContextParameter(paramName = "money") Long money);

    /**
     * TCC -- confirm
     * @param context
     */
    void confirm(BusinessActionContext context);

    /**
     * TCC -- cancel
     * @param context
     */
    void cancel(BusinessActionContext context);

}
